﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KendoMvcUI.Core;
using KendoMvcUI.Common;
using KendoMvcUI.Enums;
using System.Web.Mvc;

namespace KendoMvcUI.UI
{
    public class DatePicker:KendoUIBase
    {
        public DatePicker(KendoUIControlSettings settings,ViewContext viewContext,IViewDataContainer viewDataContainer)
            :base(settings,viewContext,viewDataContainer)
        {

        }
        public override string RenderHtml()
        {
            return "<input id=\"{0}\"/>".Formator(Settings.Id);
        }
    }
    public class DatePickerSettings : KendoUIControlSettings
    {
        public DatePickerSettings()
            : base("kendoDatePicker")
        {
            //Depth = DateDepth.month;
        }
        [PropertySetting(IsIngoreForJavaScript=true)]
        public Action<AnimationSettings> Animation { get; set; }
        /// <summary>
        /// Specifies a template used to populate value of the aria-label attribute.
        /// default: "Current focused date is #=kendo.toString(data.current, 'D')#"
        /// </summary>
        [PropertySetting(IsIngoreForJavaScript = true)]
        public string ARIATemplate { get; set; }
        /// <summary>
        /// default: "en-US"
        /// </summary>
        public string Culture { get; set; }
        [PropertySetting(IsIngoreForJavaScript = true)]
        public DateDepth? Depth { get; set; }
        /// <summary>
        /// The template which renders the footer of the calendar. If false, the footer will not be rendered.
        /// </summary>
        public string Footer { get; set; }
        /// <summary>
        /// Specifies the format, which is used to format the value of the DatePicker displayed
        /// in the input. The format also will be used to parse the input
        /// default is 'MM/dd/yyyy"
        /// </summary>
        public string Format { get; set; }
        /// <summary>
        /// Specifies the maximum date, which the calendar can show.
        /// deault is Date(2099, 11, 31)
        /// </summary>
        public DateTime? Max { get; set; }
        /// <summary>
        /// default: Date(1900, 0, 1)
        /// </summary>
        public DateTime? Min { get; set; }

        public DateTime? Value { get; set; }
        #region 事件
        public string On_Change { get; set; }
        public string On_Close { get; set; }
        public string On_Open { get; set; }
        #endregion
        public override string ToJsSettings()
        {
            string jsScript = base.ToJsSettings();
            if (!jsScript.EndsWith(","))
                jsScript += ",";
            if(Animation!=null)
            {
                AnimationSettings animation = new AnimationSettings();
                Animation(animation);
                jsScript += animation.ToString() + ",";
            }
            if (!ARIATemplate.IsNullOrWhiteSpace())
                jsScript += "ARIATemplate:'" + ARIATemplate + "'";
            if (Depth.HasValue)
                jsScript = AddOptions(jsScript, string.Format("start:'{0}',depth:'{1}'",
                    Depth.Value.ToString().LowercaseFirst(),
                    Depth.Value.ToString().LowercaseFirst()));
            if (Max.HasValue)
                jsScript = AddOptions(jsScript, string.Format("max:new Date({0},{1},{2})",
                    Max.Value.Year, Max.Value.Month - 1, Max.Value.Day));
            if (Min.HasValue)
                jsScript = AddOptions(jsScript, string.Format("min:new Date({0},{1},{2})",
                    Min.Value.Year, Min.Value.Month - 1, Min.Value.Day));
            if (Value.HasValue)
                jsScript = AddOptions(jsScript, string.Format("value:new Date({0},{1},{2})",
                    Value.Value.Year, Value.Value.Month - 1, Value.Value.Day));

            return jsScript.TrimEnd(',');
        }
    }
}
